home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac-Source 1994 July
/
Mac-Source_July_1994.iso
/
C and C++
/
Text⁄Files
/
Voyeur 1.1.1
/
Voyeur ƒ
/
v code ƒ
/
v file management.c
< prev
next >
Wrap
Text File
|
1994-02-27
|
3KB
|
116 lines
/**********************************************************************\
File: v file management.c
Purpose: This module handles opening and closing files and forks.
Voyeur -- a no-frills file viewer
Copyright ©1993-4, Mark Pilgrim
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program in a file named "GNU General Public License".
If not, write to the Free Software Foundation, 675 Mass Ave,
Cambridge, MA 02139, USA.
\**********************************************************************/
#include "v file management.h"
#include "program globals.h"
#include "msg environment.h"
#include "msg menus.h"
FSSpec gTheFS[MAX_WINDOWS];
int gTheRefNum[MAX_WINDOWS];
unsigned long gTheOffset[MAX_WINDOWS][2];
Boolean gBufferChanged[MAX_WINDOWS];
unsigned char gTheBuffer[MAX_WINDOWS][256];
unsigned long gForkLength[MAX_WINDOWS][2];
int gWhichFork[MAX_WINDOWS];
int gWhichFile;
int gLastFile;
int OpenTheFile(FSSpec *myFSS, int *thisFile)
{
OSErr theError;
long count;
CInfoPBRec pb;
pb.hFileInfo.ioCompletion=0L;
pb.hFileInfo.ioFDirIndex=0; /* very important */
pb.hFileInfo.ioVRefNum=myFSS->vRefNum;
pb.hFileInfo.ioNamePtr=myFSS->name;
pb.hFileInfo.ioDirID=myFSS->parID;
theError=PBGetCatInfo(&pb, FALSE);
if (theError!=noErr)
return diskReadErr;
gForkLength[gWhichFile][0]=pb.hFileInfo.ioFlLgLen;
gForkLength[gWhichFile][1]=pb.hFileInfo.ioFlRLgLen;
gWhichFork[gWhichFile]=((gForkLength[gWhichFile][0]==0L) ? ((gForkLength[gWhichFile][1]==0L) ? 0 : 1) : 0);
if (gWhichFork[gWhichFile]==0)
theError=OpenTheDataFork(myFSS, thisFile);
else
theError=OpenTheResourceFork(myFSS, thisFile);
if (theError!=noErr)
return diskReadErr;
gBufferChanged[gWhichFile]=FALSE;
gTheOffset[gWhichFile][0]=0L;
gTheOffset[gWhichFile][1]=0L;
return GetBuffer(*thisFile, gTheOffset[gWhichFile][gWhichFork[gWhichFile]], gTheBuffer[gWhichFile]);
}
void CloseTheFile(int fileRefNum)
{
FSClose(fileRefNum);
}
int GetBuffer(int fileRefNum, unsigned long off, unsigned char output[256])
{
long count;
OSErr theError;
int i;
count=gForkLength[gWhichFile][gWhichFork[gWhichFile]]-off<256L ? gForkLength[gWhichFile][gWhichFork[gWhichFile]]-off : 256L;
SetFPos(fileRefNum, 1, off);
theError=FSRead(fileRefNum, &count, output);
if (count!=256L)
{
for (i=count; i<256; i++)
output[i]=0x00;
}
return (theError==noErr) ? allsWell : diskReadErr;
}
OSErr OpenTheDataFork(FSSpec *myFSS, int *thisFile)
{
if (gHasFSSpecs)
return FSpOpenDF(myFSS, fsRdWrPerm, thisFile);
else
return HOpen(myFSS->vRefNum, myFSS->parID, myFSS->name, fsRdWrPerm, thisFile);
}
OSErr OpenTheResourceFork(FSSpec *myFSS, int *thisFile)
{
if (gHasFSSpecs)
return FSpOpenRF(myFSS, fsRdWrPerm, thisFile);
else
return HOpenRF(myFSS->vRefNum, myFSS->parID, myFSS->name, fsRdWrPerm, thisFile);
}